<?php
session_start();
header("Cache-control:private");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/intranet.dwt.php" codeOutsideHTMLIsLocked="true" -->
<head>
<!--[if lt IE 7]>
<script language="JavaScript">
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
window.attachEvent("onload", correctPNG);
</script>
<![endif]-->


<?php
// Connect to nanocenter database
include_once($_SERVER['DOCUMENT_ROOT'].'/utils/utils.inc.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/lib/database.class.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/lib/Auth.class.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/common.inc.php');

global $db ;
$db = new MyDatabase();
$db->Connect();

// Start session
$auth = new Auth($db);

$msg = '';
$data = cleanPostVals();

// Logout user
if (isset($_REQUEST['logout'])) {
	$auth->doLogout();   
	redirect($_SERVER['PHP_SELF']);
}else if ($_REQUEST['login']=="Login") {
	$username = $_POST['email'];
	$password = $_POST['password'];
	$msg = $auth->doLogin($username, $password, $_SERVER['PHP_SELF']);
}

// Check if logged in
$loggedUser = $auth->checkIfLoggedIn(false);
$hasIntranetAccess = false;
$hasAdminAccess = false;
if ($loggedUser) {
	$hasIntranetAccess = $loggedUser->hasIntranetAccess();
	$hasAdminAccess = $loggedUser->hasAdminAccess();
}

$action = $_REQUEST['action'];

$editUserID = getParameter('user');
$editUser = $editUserID ? new User($db, $editUserID) : $loggedUser;
if ($editUser) { $editUserID = $editUser->get_id(); }

// this is a new registration
if (!$loggedUser && $action == "register") {
	$msg = $auth->doRegisterUser($data);
	// log in the new user if registration has no errors
	if (empty($msg)) {
		$action = "";
		$user = new User($db, $_SESSION['sessionID']);
		$auth->newUserReg($msg, $action, $user);
	}
}

// this is an update user information action
if ($loggedUser && $action == "update") {

	// needs write access to db
	$db2 = new MyDatabase();
	$db2->AdminConnect();

	// check status of user's intranet access
	$intranet_access_before = $data['internet_access'];
	$msg = $auth->doEditUser($editUser, $data, $db2);
	if (empty($msg)) {
        $user = new User($db, $_SESSION['sessionID']);
		$intranet_access = $user->getValue('intranet_access');
		$msg .= "Your profile has been updated.<br>";
		if ($intranet_access == 1 && $intranet_access_before == 0) {
			$msg .= "Your request to access the Maryland NanoCenter Intranet has been received.<br>You will receive an email when it has been approved, along with your account information.";
		}
		$action = "showmsg";
	}
}
?>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Intranet @ Maryland NanoCenter</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<script language="JavaScript" src="/intranet/intranet_menu.js" type="text/javascript"></script>
<script language="JavaScript" src="/nanocenter.js" type="text/javascript"></script>
<link rel="shortcut icon" href="http://www.umd.edu/gr/favicon.ico">
<link rel="stylesheet" type="text/css" href="/intranet/intranet.css" media="screen">
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-85113-1";
urchinTracker();
</script>
<!-- InstanceParam name="SideContent" type="boolean" value="false" -->
</head>
<body onLoad="javascript: if (window.run_onLoad) { run_onLoad(); }">
<div align="center">
<table width="80%" border="0" cellspacing="0" cellpadding="0" style="max-width:1100px;min-width:990px;">
	<tr align="left" valign="top">
		<td bgcolor="#ffffff" colspan="2">
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td background="/images_old/web/header_backgrounds/nanotubes_iperez.jpg" onMouseOver="return escape('TEM image of HfO2 nanotubes.  Photo Credit: Israel Perez')" width="100%" style="background-position:top right;background-repeat:no-repeat;">
						<a href="/"><img src="/images_old/logos/nanocenter/nanocenter_logo.png" alt="Maryland NanoCenter" border="0"></a>
						<img src="/images_old/web/spacer.gif" width="500" height="1">
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr bgcolor="#FFFF99" valign="top">
		<td align="left" colspan="2">
			<table border="0" cellpadding="4" cellspacing="0">
				<tr><td><img src="/images_old/web/spacer.gif" width="2" height="1"></td>
					<td align="left"><strong>
<?php
	if($loggedUser){
?>
Welcome <?php echo getUsersName($GLOBALS['db'], $_SESSION['sessionID']);?>&nbsp;|&nbsp;<a href="<?php echo $_SERVER['PHP_SELF'];?>?logout=1">Log Out</a>&nbsp;|&nbsp;<a href="<? echo $_SERVER['PHP_SELF']; ?>?register=1">Edit Profile</a><?php
		if ($loggedUser->hasAdminAccess()) { ?>&nbsp;|&nbsp;<a href="https://<?php echo $_SERVER['HTTP_HOST'];?>/intranet/admin/">Admin</a><?php }
	}else{
?><a href="<?php echo $_SERVER['PHP_SELF'];?>?login=1">Log In</a>&nbsp;|&nbsp;<a href="<?php echo $_SERVER['PHP_SELF'];?>?register=1">Register</a><?php
	}
?></strong>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr bgcolor="#ffff99" align="left" valign="top">
		<td valign="top" width="100%">
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
<?php
if($hasIntranetAccess){

// Prints the left side Navigation Menu
// Find this function in /utils/utils.inc.php
	printIntranetMenu($loggedUser);

}
?>
					<td align="left" valign="top" width="100%">
						<table cellpadding="0" cellspacing="0" width="100%">
							<tr>
								<td align="left" valign="top">
<?php
// Login
if(isset($_REQUEST['login']) && !$loggedUser){
	printLoginForm($msg, $resume);

// Register / Edit
}else if(isset($_REQUEST['register'])){

?>
			<center>
			<div style="width: 650px; text-align:left;">
<?
	//initialize $edit variable
	$edit = 0;

	// if $action is set to showmsg then this is end of edit process, so show the resulting message
	if ($action == "showmsg") {
		if (!$loggedUser) {
			echo "<h2>Maryland NanoCenter Registration</h2>";
		}else{
			echo "<h2>Update My Profile</h2>";
		}
		echo "<table width=\"100%\"><tr><td>\n";
		echo $msg;
		echo "</td></tr></table>\n";
	} else {
	// if no message then show the edit profile form with error messages if any

		// if user is logged in and register is true then this is an edit process
		if ($loggedUser) $edit = 1;
		print_register_form($edit, $editUser, $msg);
	}

// Email password
}else if(isset($_REQUEST['forgotPassword'])){
	if (isset($_POST['changePassword'])) {
		$msg = changePassword();
	}

	if (isset($_POST['changePassword']) && empty($msg)) {
		echo "<h2>Reset My Password</h2>";
		echo "<p>Your new password has been emailed to <strong>".$_POST['email']."</strong></p>";
	} else {
		printPasswordForm($msg);
	}
}else{
?>
			<center>
			<div style="text-align:left;">
<?
	if($hasIntranetAccess){
		if(isset($_REQUEST['register'])){
			//initialize $edit variable
			$edit = 0;
			
			// if user is logged in and register is true then this is an edit process
			if ($loggedUser) $edit = 1;
			
			// if $action is set to showmsg then this is end of edit process, so show the resulting message
			if ($action == "showmsg") {
				echo "<h2>Update My Profile</h2>";
				echo "<table width=\"100%\"><tr><td>\n";
				echo $msg;
				echo "</td></tr></table>\n";
			} else {
			// if no message then show the edit profile form with error messages if any
				print_register_form($edit, $editUser, $msg);
			}
		} else {
			writeContent($db);
		}
	}else{
		if(substr_count($_SERVER['PHP_SELF'], 'travel_award')>0){
		?>
			<h2>CNST-UMD Cooperative Program: Travel Awards</h2>
			<h3>What is the travel award?</h3>
			<p>
			One of the goals of the Cooperative Program is to support U.S.
			Industrial, University, and Government research communities in the use
			of CNST Nanofabrication Facility and the CNST Collaborative Research
			Facilities. To help new users establish a working relationship with the
			CNST, the Cooperative Program will provide competitively awarded travel
			grants for approved users of the CNST facilities.
			</p>
			<p>
			Award amounts will be provided to cover up to $1000 of travel and local
			expenses for researchers traveling beyond a normal commuting distance to
			use the CNST facilities. Highest consideration for awards will be given
			to first-time users, to scientists at the early stages of their careers,
			and for expenses related to graduate student use of the facilities.
			</p>
			
			<h3>Travel Grants Applications</h3>
			<p>
			To apply for a travel award, or update your previous award, <br><br>
			<a href="<?= $_SERVER['PHP_SELF']?>?login=1">please log in here</a>	or <a href="<?= $_SERVER['PHP_SELF']?>?register=1">create a password-protected login</a>.
			</p>
			
			<p>
			The process of registering for new users is straightforward and will direct you immediately to the appropriate travel grant page.  Be sure to retain your log in information for future access.
			</p>
		<?
		}else{
?>
<h2>Maryland NanoCenter Intranet</h2>
<p>
You are trying to view a NanoCenter Intranet page.
<br><br>
Only registered users with Intranet authorization may access content within the Intranet.
<br><br>
To view this page you must log in and have Intranet access.
</p>

<?
	if($loggedUser){
		echo "<font size='3' color='#330000'><strong>Your Intranet Access Status: ".$loggedUser->intranetRequestStatus()."</strong></font><br>";
	}else{
?>

<br>
<br>
<a href="<? echo $_SERVER['PHP_SELF'];?>?login=1">Click here to log in.</a><br>
<br>
- or -<br>
<br>
<a href="<? echo $_SERVER['PHP_SELF'];?>?register=1">Click here to register and request Intranet access.</a><br>
<br>
- or -<br>
<br>
<a href="/">Click here to go back to the public site.</a><br>
<?	}

}
?>
<br>
<br>
<br>
<?php
	}
}
?>
			</div>
			</center>

<?
function writeContent($db){
?>
<div>
<!-- vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv  Put your content below  vvvvvvvvvvvvvvvvvvvvvvvvvvvv -->
<!-- InstanceBeginEditable name="Content" -->
<h2>NanoCenter Equipment Scheduler Overview</h2>
<ol>
<li>Scope</li>
<li></li>
<ol><li></li>
	<li></li>
</ol>
<li></li>
</ol>
<!-- InstanceEndEditable -->								
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  Put your content above  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -->
</div>
<div style="clear:both;">
							</td>
							<td align="left" valign="top" width="30%">

<?php
}
?>

							</td>
						</tr>
					</table>
				</td>
			</table>
		</td>
	</tr>
	<tr align="center" valign="top">
		<td bgcolor="#FFFF99" class="footer" colspan="2">
			<br><br>
			<p align="center"><a href="http://eng.umd.edu/" target="_blank"><img src="/images/logos/logos-UMD/logo_clark.gif" alt="A. James Clark School of Engineering" title="A. James Clark School of Engineering" border="0" align="middle"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.cmns.umd.edu/" target="_blank"><img src="/images/logos/logos-UMD/cmns_logo.gif" alt="College of Computer, Mathematical, and Natural Sciences" title="College of Computer, Mathematical, and Natural Sciences" border="0" align="middle"></a></p>
			Problems? <a href="mailto:webmaster@nanocenter.umd.edu?subject=Problem on MCINSE website&body=Error on page <?php echo basename($_SERVER['SCRIPT_FILENAME']);?>%0d%0a">Contact Us</a><br>
			&copy; 2005 | <a href="http://www.umd.edu" class="footer">University of Maryland</a> | <a href="http://www.nethics.umd.edu/dive-in/privacy.html" class="footer">Privacy</a>
		</td>
	</tr>
</table>
</div>
<script language="JavaScript" type="text/javascript" src="/wz_tooltip.js"></script>
</body>
<?php
$db->Disconnect();
?>
<!-- InstanceEnd --></html>